import { BaseCommand, CMEVENTS } from '@amcax/base';
import { userEvents } from '../../../../module';

const openPanel = async () => {
  let defaultPanel = 'input';
  const task_res = localStorage.getItem('task_result');
  if (task_res) {
    defaultPanel = 'result';
  }
  // userEvents.emit(CMEVENTS.RIGHT_NAV_ITEM_CLICK, {
  //   id: defaultPanel,
  //   component: false,
  // });
  userEvents.emit(CMEVENTS.WIDGET_RIGHT_NAV_SHOW, {
    show: true,
    id: defaultPanel,
  });
};

export const cmdPolarCurve: BaseCommand = {
  id: 'cmdPolarCurve',
  label: '翼型极曲线',
  icon: 'commands/airfoil/polar-curve',
  invoke: openPanel,
  initialDisabled: true,
  subscribeDisabled: (setDisabled: (disabled: boolean) => void) => {
    const listener = (empty: boolean) => {
      setDisabled(empty);
    };
    userEvents.on('sceneEmpty', listener);
    return () => userEvents.off('sceneEmpty', listener);
  },
};
